const state = {
    tree_selected_arr: [],
    wrapObj: {}
  };
  
  const getters = {};
  
  const mutations = {
      addTaskArr: (state, data) => {
        //   if (!state.wrapObj[data['label'] + data['sn']]) {
        //       var obj = {}
        //   let { label, chns, sn, parent_label } = data;
        //       obj["sn"] = sn;
        //       obj["device_name"] = parent_label ? parent_label : label;
        //       obj["channel"] = typeof chns == 'number' ? chns.toString() : '';
        //       obj["play_order"] = -1;
        //       state.tree_selected_arr.push(obj)
        //       state.wrapObj[obj['device_name'] + obj['sn']] = 1
        //   }
        var obj = {}
        let { label, chns, sn, parent_label } = data;
            obj["sn"] = sn;
            obj["device_name"] = parent_label ? parent_label : label;
            obj["channel"] = typeof chns == 'number' ? chns.toString() : '';
            obj["play_order"] = -1;
            state.tree_selected_arr.push(obj)
            state.wrapObj[obj['device_name'] + obj['sn']] = 1
      },
      initTaskArr: (state, data) => {
          state.tree_selected_arr = data
      },
      initObj: (state) => {
        //   let arr = state.tree_selected_arr
        //   if (Array.isArray(arr) && arr.length > 0) {
        //     for (let i = 0; i < arr.length; i++){
        //         state.wrapObj[arr[i]['device_name']+arr[i]['sn']] = 1 
        //       }
        //   }  
      },
      removeTaskArr: (state, data) => {
          state.tree_selected_arr.splice(data.index, 1)
        //   delete state.wrapObj[data['item']['device_name']+data['item']['sn']]
    },
  };
  
  const actions = {};
  
  export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
  };